<% if flash[:notice]  -%>
  <div class="sysmsg"><%= flash[:notice] -%></div>
  <% flash[:notice] = nil -%>
<% end -%>

<table id="columns">
  <tr>
    <!-- Main Messages -->
    <td id="main">
      <div id="update">
        <% form_tag({:controller => :direct_message, :action => "to"},
          :method => :post, :class => "limit", :id => "privatemessage") do -%>
        <h2>Sent direct message to <%= select("user", "id", @friend_list.collect {|friend| [friend.display_name, friend.id]}) -%>.</h2> 
        <p> 
          <textarea name="content" rows="3" cols="70" class="qs"></textarea> 
        </p> 
        <p class="act"> 
          <input type="submit" class="formbutton" title="Post" value="Post" /> 
        </p> 
        <p class="tip">You can input up to 140 charactors.</p>  
        <% end -%>
      </div>
      
      <div id="content">
        <div id="stream" class="pm">
          <ol class="wa">
            <% @dm.each do |message| -%>
            <% user = '' -%>
              <% if message.post_from == @user.id -%>
                <li class="unlight">
                  <% user = User.find(message.post_to) -%>
                  <%= link_to(image_tag(user.avatar, :alt => user.display_name).to_s, {:controller => :message, :action => :user, :id => user.id}, :class => "avatar", :title => user.display_name.to_s) -%>
                  <span class="content"><%= "Send to " + link_to(user.display_name, {:controller => :message, :action => :user, :id => user.id}, :title => user.display_name.to_s).to_s + ": "+ h(message.content) -%></span>
              <% else -%>
                <li class="unlight" style="background-color: #DDDDDD">
                  <% user = User.find(message.post_from) -%>
                  <%= link_to(image_tag(user.avatar, :alt => user.display_name).to_s, {:controller => :message, :action => :user, :id => user.id}, :class => "avatar", :title => user.display_name.to_s) -%>
                  <span class="content"><%= "Send from " + link_to(user.display_name, {:controller => :message, :action => :user, :id => user.id}, :title => user.display_name.to_s).to_s + ": "+ h(message.content) -%></span>
              <% end -%>
                <span class="stamp time"><%= "Sent about " + time_string(Time.now.to_i - message.post_at.to_i) + " ago" -%></span>
                <span class="op"><a class="post_act" href="/direct_message/to/<%= user.id -%>">回复</a></span>
              </li>
            <% end -%>
          </ol>
        </div>
        <!-- Paging will add later. -->
      </div>
    </td>
    
    <!-- Sidebar -->
    <!-- All the following values will be replaced by varibles -->
    <td id="sidebar">
      <div id="user_top">
        <a href="/message"><%= image_tag(@user.avatar) -%>
        <h2><%= @user.display_name -%></h2></a>
      </div>
      <ul id="user_stats">
        <li>
          <a href="/friend">
            <span class="count"><%= Follower.friend_count(@user.id) -%></span>
            <span class="label">Friends</span>
          </a>
        </li>
        <li>
          <a href="/friend?opt=f">
            <span class="count"><%= Follower.follower_count(@user.id) -%></span>
            <span class="label">Followers</span>
          </a>
        </li>
        <li>
          <a href="/message">
            <span class="count"><%= Message.message_count(@user.id) -%></span>
            <span class="label">Messages</span>
          </a>
        </li>
      </ul>
      <div class="stabs">
        <ul>
          <li class="Current">
            <a href="/home">
              <span class="label">Home</span>
            </a>
          </li>
          <li>
            <a href="/message/at">
              <span class="label">@Replies</span>
            </a>
          </li>
          <li>
            <a href="/direct_message">
              <span class="label">Direct Messages (<%= @dm_count -%>)</span>
            </a>
          </li>
          <li>
            <a href="/favorite">
              <span class="label">Favorites</span>
            </a>
          </li>
        </ul>
      </div>
    </td>
  </tr>
</table>
